package com.miao.entity;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.*;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

public class Food implements InitializingBean, DisposableBean, BeanNameAware, BeanFactoryAware, ApplicationContextAware {

    private  String name;
    private  String colo;

    //构造方法
    public Food(String name, String colo) {
        this.name = name;
        this.colo = colo;
        System.out.println("==》Bean创建：Food(String name, String colo)构造方法");
    }
    public Food() {
        System.out.println("==》Bean创建：Food()构造方法");
    }

    //getter setter
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
        System.out.println("==》Set方法注入属性：setName");
    }

    public String getColo() {
        return colo;
    }
    public void setColo(String colo) {
        this.colo = colo;
        System.out.println("==》Set方法注入属性：setColo");
    }

    //自定义初始化方法
    public void myInit(){
        System.out.println("==》自定义初始化方法：init()");
    }

    //自定义的销毁方法
    public void myDestroy(){
        System.out.println("==》自定义销毁方法：destroy()");
    }

    //InitializingBean接口
    @Override
    public void afterPropertiesSet() throws Exception {
        System.out.println("==》InitializingBean接口：afterPropertiesSet()方法");
    }


    //DisposableBean接口
    @Override
    public void destroy() throws Exception {
        System.out.println("==》DisposableBean接口：destroy()方法");
    }


    //BeanNameAware
    @Override
    public void setBeanName(String name) {
        System.out.println("==》BeanNameAware接口：setBeanName()方法");
    }

    //BeanFactoryAware
    @Override
    public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
        System.out.println("==》BeanFactoryAware接口：setBeanFactory()方法");
    }

    //ApplicationContextAware
    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        System.out.println("==》ApplicationContextAware接口：setApplicationContext()方法");
    }


    @Override
    public String toString() {
        return "Food{" +
                "name='" + name + '\'' +
                ", colo='" + colo + '\'' +
                '}';
    }


}
